#include "DerivationTree.h"
#include "CallInstruction.h"
#include <cmath>
using namespace std;

MinusNode::MinusNode() : NodeTree_CRTP<MinusNode>() { }

MinusNode::MinusNode(const AutoPointer<NodeTree>& _left, const AutoPointer<NodeTree>& _right) : NodeTree_CRTP<MinusNode>(), left(_left), right(_right) { }

MinusNode::MinusNode(const MinusNode& copy) : NodeTree_CRTP<MinusNode>(copy), left(copy.left), right(copy.right) { }

bool MinusNode::execute(Pointer<LeonardVirtualMachine> LVM) {
	left->execute(LVM);
	right->execute(LVM);
	AutoPointer<TreeExpression::Expression> second = LVM->top();
	LVM->pop();
	AutoPointer<TreeExpression::Expression> first = LVM->top() ;
	LVM->pop();
	first->addLeaf(second);
	TreeExpression::CallInstruction* minusCall = new TreeExpression::CallInstruction("operator-");
	minusCall->setSon(first);
	AutoPointer<TreeExpression::Expression> ris(minusCall);
	LVM->push(ris);
	return true;
}
